//
//  YTJoinUsController.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/8/7.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTJoinUsController.h"

@interface YTJoinUsController ()
@property (weak, nonatomic) IBOutlet UIImageView *bgImageView;
@property(nonatomic ,strong)NSString *wechatNum;
@end

@implementation YTJoinUsController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    
    [YTNetworkManager.shareManager requestJoinUsWithCompletion:^(NSDictionary *dict, NSString *error) {
        
        if (error) {
            [self.view showTipWithTipStr:error];
            return ;
        }
      

        
        [self.bgImageView sd_setImageWithURL:[NSURL URLWithString:dict[@"imgUrl"]] placeholderImage:nil options:SDWebImageRefreshCached];
        self.wechatNum = dict[@"wechat"];
    }];
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage dh_setNavImageName:@"倛袨1"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClick)];
    


    
    UIBarButtonItem *copyButton = [[UIBarButtonItem alloc] initWithTitle:@"复制微信号" style:UIBarButtonItemStylePlain target:self action:@selector(copyWechat)];
    
    self.navigationItem.rightBarButtonItem = copyButton;
    
    [copyButton setTintColor:kBackButtonColor];
    [copyButton setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14]} forState:UIControlStateNormal];
}

- (void)copyWechat
{
    if (!self.wechatNum) {
        [self.view showTipWithTipStr:@"网络不给力..."];
        return;
    }
    [self copyStringToPasteBoard:self.wechatNum];
    
}
- (void)copyStringToPasteBoard:(NSString *)str
{
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = str;
    
    [self.view showTipWithTipStr:@"复制成功"];
}
// 返回按钮
- (void)backButtonClick
{
    [self.navigationController popViewControllerAnimated:true];

}



@end
